package j02tree;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class J1 {
    public static void main(String[] args) {
        TreeSet<Integer> arr = new TreeSet<>(
                (num1,num2)->num2-num1
        );
        arr.add(2);
        arr.add(4);
        arr.add(1);
        arr.add(66);
        arr.add(23);
        arr.add(1);
        System.out.println("arr = " + arr);

        System.out.println("===");
//        TreeSet<String> arr2 = new TreeSet<>();
//        TreeSet<String> arr2 = new TreeSet<>(
//                new Comparator<String>() {
//                    @Override
//                    public int compare(String o1, String o2) {
//                        return o2.compareTo(o1);
//                    }
//                }
//        );
        TreeSet<String> arr2 = new TreeSet<>(
                (s1,s2)->s2.compareTo(s1)
        );
        arr2.add("ww");
        arr2.add("ff");
        arr2.add("bb");
        arr2.add("zz");
        arr2.add("xx");
        System.out.println("arr2 = " + arr2);
        System.out.println(arr2.first());//zz
        System.out.println("====");
        Iterator<String> it = arr2.descendingIterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
}
